home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ident / servers / tops20-identd.mac < prev    next >
Encoding:
Text File  |  1992-05-31  |  7.1 KB  |  281 lines

  1.     TITLE    IDENTD - TCP port user identification server
  2.     SEARCH    MONSYM,MACSYM
  3.  
  4. ;;; IDENTD server for TOPS-20 (using the IDENT protocol of RFC ????), written
  5. ;;; by Anders Andersson (Anders.Andersson@DoCS.UU.SE), Update Computer Club.
  6. ;;; This code is put into the public domain.  Do whatever you like with it.
  7. ;;; I can't provide any support, but you are welcome to tell me your opinions
  8. ;;; about it.
  9. ;;;
  10. ;;; This code makes use of the unsupported STAT% and MONRD% system calls (as
  11. ;;; does SYSDPY) to obtain information about TCP ports.  The MONRD% call needs
  12. ;;; to be installed in the monitor beforehand, by having "SYSDPY E" run with
  13. ;;; WHEEL capability at system startup if by no other means.
  14. ;;;
  15. ;;; This server operates on a single local interface only.  By default,
  16. ;;; interface #0 is used.  In order to use a different interface, deposit its
  17. ;;; number in location INTNUM before starting the server.
  18. ;;;
  19. ;;; This server is single-threaded, meaning that it may easily be blocked by
  20. ;;; a slow, broken, or plain evil client that fails to provide input.  This is
  21. ;;; the next thing that needs to be fixed (perhaps NETSRV can help)...
  22.  
  23. ;;; This code was last hacked May 31, 1992.
  24. ;;; 36 >> 32!
  25.  
  26. VERMAJ=    1
  27. VERMIN=    0
  28. VEREDT=    ^D31
  29. VERWHO=    2
  30.  
  31. IDPORT=    ^D113            ;according to RFC 931, ????
  32.  
  33. ECODE=    6            ;error code
  34. TCBCNT=    7            ;TCB counter
  35. LPORT=    11            ;number of local port
  36. FPORT=    12            ;number of foreign port
  37. LHOST=    13            ;address of local host
  38. FHOST=    14            ;address of foreign host
  39.  
  40. TCB:    BLOCK    <TCBSIZ==200>    ;storage for retrieved TCB info
  41. NAMBUF:    BLOCK    <^D50/5+1>    ;buffer for TCP: file name string
  42. HLABUF:    BLOCK    <HLASIZ==10>    ;local host address buffer
  43. LINBUF:    BLOCK    <<LINSIZ==^D20>/5+1>    ;command line buffer
  44. ATMBUF:    BLOCK    <<ATMSIZ==^D10>/5+1>    ;command atom buffer
  45. ANSWER:    BLOCK    <^D80/5+1>    ;buffer for answer text
  46.  
  47. CSB:    EXP    <CM%XIF!0>    ;no indirect files, no reparse possible
  48.     EXP    <0,,.NULIO>    ;we don't want any output from COMND%
  49.     EXP    <-1,,[ASCIZ //]>    ;null prompt
  50.     BLOCK    1
  51.     BLOCK    1
  52.     BLOCK    1
  53.     BLOCK    1
  54.     BLOCK    1
  55.     BLOCK    1
  56.     EXP    <0>        ;no GTJFN% block needed
  57.  
  58. TCPJFN:    BLOCK    1        ;IDENT client file handle
  59. ANSPTR:    BLOCK    1        ;pointer into answer buffer
  60. USERNO:    BLOCK    1        ;number of user owning job
  61.  
  62. INTNUM:    EXP    <0>        ;interface# (change this as appropriate)
  63.  
  64. EVEC:    JRST    START
  65.     JRST    REENT
  66.     BYTE    (3)VERWHO(9)VERMAJ(6)VERMIN(18)VEREDT
  67.  
  68. ERRTXT:    EXP    [ASCIZ /INVALID-PORT/]
  69.     EXP    [ASCIZ /NO-USER/]
  70.     EXP    [ASCIZ /UNKNOWN-ERROR/]
  71.  
  72. ERRIP=    1
  73. ERRNU=    2
  74. ERRUE=    3
  75.  
  76. START:    RESET%
  77. REENT:    MOVEI    1,.GTHLA
  78.     MOVEI    3,HLABUF
  79.     MOVEI    4,HLASIZ
  80.     GTHST%            ;obtain all local addresses
  81.      ERJMP    FATAL
  82.     MOVE    1,INTNUM    ;this is the selected interface #
  83.     CAIL    1,0        ;negative interface #?
  84.      CAML    1,4        ;within the range of existing interfaces?
  85.       JRST    NONINT        ;the specified interface does not exist
  86.     MOVE    LHOST,HLABUF(1)    ;pick the corresponding local address
  87.     HRROI    1,NAMBUF    ;create a file name string for GTJFN%
  88.     HRROI    2,[ASCIZ /TCP:/]
  89.     MOVEI    3,0
  90.     SOUT%
  91.      ERJMP    FATAL
  92.     MOVE    2,LHOST
  93.     MOVE    3,[NO%MAG!NO%LFL!NO%ZRO!FLD(^D11,NO%COL)!FLD(^D8,NO%RDX)]
  94.     NOUT%
  95.      ERJMP    FATAL
  96.     MOVEI    2,"-"
  97.     IDPB    2,1
  98.     MOVEI    2,IDPORT
  99.     MOVEI    3,^D10
  100.     NOUT%
  101.      ERJMP    FATAL
  102.     MOVEI    2,"V"-"@"    ;insert a ^V
  103.     IDPB    2,1        ;we want this source file to be mailable
  104.     HRROI    2,[ASCIZ /#..0;CONNECTION:PASSIVE/]
  105.     MOVEI    3,0
  106.     SOUT%
  107.      ERJMP    FATAL
  108. LISTEN:    SETZB    LPORT,FPORT    ;destroy possible garbage
  109.     HRROI    1,LINBUF    ;set up CSB pointers and counters
  110.     MOVEM    1,CSB+.CMBFP
  111.     MOVEM    1,CSB+.CMPTR
  112.     MOVEI    1,LINSIZ
  113.     MOVEM    1,CSB+.CMCNT
  114.     MOVEM    1,CSB+.CMINC
  115.     HRROI    1,ATMBUF
  116.     MOVEM    1,CSB+.CMABP
  117.     MOVEI    1,ATMSIZ
  118.     MOVEM    1,CSB+.CMABC
  119.     MOVE    1,[GJ%SHT!GJ%OLD!0]    ;establish a server port...
  120.     HRROI    2,NAMBUF
  121.     GTJFN%
  122.      ERJMP    FATAL
  123.     MOVE    2,[FLD(^D8,OF%BSZ)!FLD(.TCMWI,OF%MOD)!OF%RD!OF%WR]
  124.     OPENF%            ;wait for a client to connect...
  125.      ERJMP    FATAL
  126.     MOVEM    1,TCPJFN
  127.     HRLM    1,CSB+.CMIOJ    ;input JFN
  128.     GDSTS%            ;get info about the client
  129.      ERJMP    FATAL
  130.     MOVEM    3,FHOST        ;save client host
  131.     MOVEI    ECODE,ERRIP    ;default error message: invalid port
  132.     MOVEI    1,CSB
  133.     MOVEI    2,[FLDDB.(.CMINI)]
  134.     COMND%
  135.      ERJMP    CFATAL
  136.     TLNE    1,(CM%NOP)
  137.      JRST    MREPLY
  138.     MOVEI    2,[FLDDB.(.CMNUM,CM%SDH,^D10)]
  139.     COMND%            ;parse local port number
  140.      ERJMP    CFATAL
  141.     TLNE    1,(CM%NOP)
  142.      JRST    MREPLY
  143.     MOVE    LPORT,2
  144.     MOVEI    2,[FLDDB.(.CMCMA,CM%SDH)]
  145.     COMND%            ;parse a comma
  146.      ERJMP    CFATAL
  147.     TLNE    1,(CM%NOP)
  148.      JRST    MREPLY
  149.     MOVEI    2,[FLDDB.(.CMNUM,CM%SDH,^D10)]
  150.     COMND%            ;parse foreign port number
  151.      ERJMP    CFATAL
  152.     TLNE    1,(CM%NOP)
  153.      JRST    MREPLY
  154.     MOVE    FPORT,2
  155.     MOVEI    2,[FLDDB.(.CMCFM,CM%SDH)]
  156.     COMND%            ;parse CRLF
  157.      ERJMP    CFATAL
  158.     TLNE    1,(CM%NOP)
  159.      JRST    MREPLY
  160.     TDNN    LPORT,[^-177777]
  161.      TDNE    FPORT,[^-177777]
  162.       JRST    MREPLY        ;check that port numbers are within range
  163.     MOVEI    ECODE,0        ;no error so far
  164. MREPLY:    HRROI    1,ANSWER    ;put some port numbers back in reply
  165.     MOVEI    3,^D10
  166.     MOVE    2,LPORT
  167.     NOUT%
  168.      ERJMP    FATAL
  169.     MOVEI    2,","
  170.     IDPB    2,1
  171.     MOVE    2,FPORT
  172.     NOUT%
  173.      ERJMP    FATAL
  174.     MOVEM    1,ANSPTR
  175.     CAIE    ECODE,0        ;was there an error?
  176.      JRST    EREPLY        ;then make this an error reply
  177.     HRLZI    1,(TCP%NI)
  178.     STAT%            ;get number of TCBs
  179.      ERJMP    FATAL
  180.     MOVE    TCBCNT,2
  181. TCLOOP:    HRLI    1,(TCP%IX)
  182.     HRR    1,TCBCNT
  183.     MOVSI    2,-200
  184.     MOVE    3,[-200,,TCB]
  185.     STAT%            ;retrieve current TCB
  186.      ERJMP    FATAL
  187.     CAMN    FHOST,TCB+7    ;the wanted foreign host?
  188.      CAME    LHOST,TCB+10    ;the wanted local host also?
  189.       JRST    TCNEXT        ;no, ignore this one
  190.     CAMN    FPORT,TCB+11    ;the requested foreign port?
  191.      CAME    LPORT,TCB+12    ;the requested local port also?
  192.       JRST    TCNEXT        ;no, ignore this one
  193.     MOVEI    1,16
  194.     HLRZ    2,TCB+6        ;get monitor local job number
  195.     MONRD%            ;convert to cluster (?) global job number
  196.      ERJMP    FATAL
  197.     MOVE    1,2        ;find out user of job
  198.     MOVE    2,[-1,,USERNO]
  199.     MOVEI    3,.JIUNO
  200.     GETJI%
  201.      ERJMP    FATAL
  202.     MOVE    1,ANSPTR
  203.     HRROI    2,[ASCIZ /:USERID:TOPS20:/]
  204.     MOVEI    3,0
  205.     SOUT%
  206.      ERJMP    FATAL
  207.     MOVE    2,USERNO    ;translate to user name string
  208.     DIRST%
  209.      ERJMP    FATAL
  210.     JRST    TCPUSH        ;go tell all to the client (ptr in AC1)
  211.  
  212. NONINT:    HRROI    1,[ASCIZ /IP interface /]
  213.     ESOUT%
  214.     MOVEI    1,.PRIOU
  215.     MOVE    2,INTNUM
  216.     MOVEI    3,^D8
  217.     NOUT%
  218.      ERJMP    FATAL
  219.     HRROI    1,[ASCIZ / does not exist -- change INTNUM and continue
  220. /]
  221.     PSOUT%
  222.     HALTF%
  223.     JRST    START
  224.  
  225. TCNEXT:    AOBJN    TCBCNT,TCLOOP
  226.     MOVEI    ECODE,ERRNU    ;no matching ports in use found
  227. EREPLY:    MOVE    1,ANSPTR
  228.     HRROI    2,[ASCIZ /:ERROR:/]
  229.     MOVEI    3,0
  230.     SOUT%
  231.      ERJMP    FATAL
  232.     HRRO    2,ERRTXT-1(ECODE)
  233.     MOVEI    3,0
  234.     SOUT%
  235.      ERJMP    FATAL
  236. TCPUSH:    MOVEI    2,"M"-"@"    ;be sure buf ptr is in AC1 here
  237.     IDPB    2,1
  238.     MOVEI    2,"J"-"@"
  239.     IDPB    2,1
  240.     MOVEI    3,0        ;terminate string with a NUL byte
  241.     IDPB    3,1
  242.     MOVE    1,TCPJFN
  243.     SETZM    TCPJFN        ;don't tell client about errors after this
  244.     HRROI    2,ANSWER
  245.     SOUT%
  246.      ERJMP    FATAL
  247.     MOVEI    2,.TCPSH    ;this is our last word
  248.     TCOPR%
  249.      ERJMP    FATAL
  250.     CLOSF%
  251.      ERJMP    FATAL
  252.     JRST    LISTEN        ;go wait for our next client
  253.  
  254. CFATAL:    MOVEI    1,.FHSLF    ;COMND% had an error, check what it is
  255.     GETER%
  256.     HRRZ    2,2
  257.     CAIE    2,COMNX2    ;field too long?
  258.      CAIN    2,COMNX3    ;command too long?
  259.       JRST    MREPLY        ;client's fault, go tell him
  260.     CAIN    2,COMNX9    ;end of input?
  261.      JRST    MREPLY        ;also client's fault
  262. ;    JRST    FATAL        ;else fall through and tell us
  263. FATAL:    HRROI    1,[ASCIZ /JSYS error - /]
  264.     ESOUT%
  265.     MOVEI    1,.PRIOU
  266.     HRLOI    2,.FHSLF
  267.     MOVEI    3,0
  268.     ERSTR%
  269.      NOP            ;never mind
  270.      NOP            ;fat chance
  271.     HRROI    2,[ASCIZ /
  272. /]
  273.     PSOUT%
  274.     MOVEI    ECODE,ERRUE    ;this is not a normal error
  275.     SKIPE    TCPJFN        ;do we have a connection?
  276.      JRST    EREPLY        ;then try to finish it and continue
  277.     HALTF%            ;else die...
  278.     JRST    .-1        ;...and stay there
  279.  
  280.     END    <3,,EVEC>
  281.